package com.easygem.controller.front;

import com.easygem.common.annotation.ControllerEndpoint;
import com.easygem.common.error.SystemException;
import com.easygem.common.response.ResponseBean;
import com.easygem.common.vo.front.LabelInfoVo;
import com.easygem.front.service.LabelInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author luoxi
 * @version 1.0
 * @className LabelInfoController
 * @Description TODO
 * @date 2025/1/1 18:43
 */
@Api(tags = "标签")
@RestController
@RequestMapping("/system/labelInfo")
public class LabelInfoController {
    @Autowired
    private LabelInfoService labelInfoService;
    /**
     * 标签类型
     * @return
     */
    @ApiOperation(value = "所有标签")
    @GetMapping("/findAll")
    @ResponseBody
    public ResponseBean<List<LabelInfoVo>> findAll(@RequestParam(value = "accountName", defaultValue = "" ) String accountName) {
        List<LabelInfoVo> labelInfo = labelInfoService.getLabelInfoAll(accountName);
        return ResponseBean.success(labelInfo);
    }

    /**
     * 标签下拉列表框
     *
     * @return
     */
    @ApiOperation(value = "标签列表", notes = "通过标签id查询")
    @GetMapping("/findList")
    @ResponseBody
    public ResponseBean<List<LabelInfoVo>> findList(@RequestParam(value = "accountName", defaultValue = "" ) String accountName) {
        List<LabelInfoVo> labelInfoVos=labelInfoService.selectLabelInfo(accountName);
        return ResponseBean.success(labelInfoVos);
    }
    /**
     * 添加标签
     * @return
     */
    @ControllerEndpoint(exceptionMessage = "添加标签失败", operation = "添加标签")
    @RequiresPermissions({"DataDictionary:add"})
    @ApiOperation(value = "添加标签")
    @PostMapping("/add")
    @ResponseBody
    public ResponseBean add(@RequestBody @Validated LabelInfoVo labelInfoVo) {
        labelInfoService.add(labelInfoVo);
        return ResponseBean.success();
    }


    /**
     * 编辑标签
     *
     * @param id 编号
     * @return
     */
    @ApiOperation(value = "编辑标签")
    @RequiresPermissions({"DataDictionary:edit"})
    @GetMapping("/edit/{id}")
    @ResponseBody
    public ResponseBean edit(@PathVariable Integer id) throws SystemException {
        LabelInfoVo labelInfoVo = labelInfoService.edit(id);
        return ResponseBean.success(labelInfoVo);
    }

    /**
     * 更新标签操作
     *
     * @return
     */
    @ControllerEndpoint(exceptionMessage = "更新标签失败", operation = "更新标签")
    @ApiOperation(value = "更新标签")
    //@RequiresPermissions({"industry:update"})
    @PutMapping("/update/{id}")
    @ResponseBody
    public ResponseBean update(@PathVariable Integer id,@RequestBody @Validated LabelInfoVo labelInfoVo) throws SystemException {
        labelInfoService.update(id,labelInfoVo);
        return ResponseBean.success();
    }
}
